package com.rongzhe.house.presenter;

import android.content.Intent;

import com.rongzhe.house.entity.voo.City;
import com.rongzhe.house.internet.DataListener;
import com.rongzhe.house.manager.PositionManager;
import com.rongzhe.house.ui.UiControlInterface;
import com.rongzhe.house.ui.activity.ChooseCityActivity;

import java.util.List;

/**
 * Created by huang on 2017/11/26.
 */

public class ChooseCityPresenter extends BasePresenter {
    public ChooseCityPresenter(UiControlInterface uiControlInterface) {
        super(uiControlInterface);
    }

    @Override
    public void start(Intent intent) {
        loadCitys();
    }

    public void onClityItemClick(City city) {
        PositionManager.getInstance().setCurrentCity(city);
        getUiControlInterface().finish();
    }

    private void loadCitys() {
        PositionManager.getInstance().loadAllCity(
                new DataListener<List<City>>() {
            @Override
            public void onSuccess(List<City> data, String message) {
                ((ChooseCityActivity)getUiControlInterface()).setListCity(data);
            }

            @Override
            public void onFailed(Throwable error, String message) {
                getUiControlInterface().showToast(message);
            }

            @Override
            public void onEnd() {

            }
        });
    }
}
